package cn.wind.xboot.module.web.controller.sys;

import cn.wind.xboot.core.annotation.RestJsonController;
import cn.wind.xboot.core.res.ApiResult;
import cn.wind.xboot.logic.sys.entity.SysDictType;
import cn.wind.xboot.framework.domain.PageVo;
import cn.wind.xboot.framework.domain.SearchVo;
import cn.wind.xboot.framework.web.controller.BaseController;
import cn.wind.xboot.module.web.vo.sys.DictTypeVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>Title: DictController</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/8/7
 */
@Slf4j
@RestJsonController
@Api(value = "dict", tags = "字典管理接口")
@RequestMapping("dict/type")
@Validated
public class DictTypeController extends BaseController<SysDictType, Long> {
    @Override
    public IService getService() {
        return sysDictTypeService;
    }

    @GetMapping
    public ApiResult get(DictTypeVo dictTypeVo, PageVo pageVo, SearchVo searchVo) {
        return ApiResult.Custom().success().add(sysDictTypeService.page(pageVo.init(),new QueryWrapper<SysDictType>()));
    }

    @PostMapping
    public ApiResult save(DictTypeVo entity) throws Exception {
        return super.save(beanMapper.map(entity,SysDictType.class));
    }

    @PutMapping
    public ApiResult edit(DictTypeVo dictTypeVo) {
        SysDictType sysDictType = beanMapper.map(dictTypeVo, SysDictType.class);
        return super.edit(sysDictType, new QueryWrapper<SysDictType>().lambda().eq(SysDictType::getId, dictTypeVo.getId()));
    }

    @Override
    public ApiResult delete(@RequestParam Long[] ids) {
        return super.delete(ids);
    }
}
